# !/usr/bin/env python
# encoding: utf-8


"""
  @author: gaogao
  @file: parse_txt.py
  @time: 2022/4/14 14:11
  @desc:
"""
import pathlib

import numpy as np
import pandas as pd

# fn = "D:\PyCharmProject\HC_ATS\static\SubDie.txt"


def parse_txt_to_dict(fn):
    meta_data = np.loadtxt(fn, dtype=str, delimiter=",")
    final_data = meta_data[1:]
    result = {}
    for value in final_data:
        result[value[0].strip(",")] = [i.strip(",").strip() for i in value[1:]]
    if result:
        return result


def func(listTemp, n):
    for i in range(0, len(listTemp), n):
        yield listTemp[i:i + n]


# result = parse_txt_to_dict(fn)
# current = "D1"
# if current in result:
#     list_keys = list(result.keys())
#     current_index = list_keys.index(current)
#     next_index = 0 if current_index == len(list_keys) - 1 else current_index + 1
#     current_array = np.array(result[list_keys[current_index]], dtype=np.float32)
#     next_array = np.array(result[list_keys[next_index]], dtype=np.float32)
#     # print(result[list_keys[next_index]])
#     print("next",next_array)
#     # print(result[list_keys[current_index]])
#     print("current",current_array)
#     final_array = next_array - current_array
#     result = func(final_array, 2)
#     print(list(result))
    # for i in range(len(result[list_keys[current_index]])):
    #     print(result[list_keys[current_index]][i])
    #     print(result[list_keys[next_index]][i])

# for key, value in result.items():
#     print(key, value)
